package uhaleks;

/**
 * Класс Равнобедренная трапеция
 *
 * @version 1.1       02.07.2014, 05.07.2014
 * @author            Александр Уханов
 */
enum Side { LEFT, TOP, RIGHT, BOTTOM }

public class IsoscelesTrapezoid {
    private int x1, y1, x2, y2, x3, y3, x4, y4;
    public IsoscelesTrapezoid(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
        this.x1 = x1;
        this.y1 = y1;
        this.x2 = x2;
        this.y2 = y2;
        this.x3 = x3;
        this.y3 = y3;
        this.x4 = x4;
        this.y4 = y4;
    }
    public double sideLength(Side side) {
        switch (side) {
            case LEFT:
                return Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
            case TOP:
                return Math.sqrt((x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2));
            case RIGHT:
                return Math.sqrt((x4 - x3) * (x4 - x3) + (y4 - y3) * (y4 - y3));
            case BOTTOM:
                return Math.sqrt((x1 - x4) * (x1 - x4) + (y1 - y4) * (y1 - y4));
            default:
                return 0d;
        }
    }
    public boolean checkIsosceles() {
        return (sideLength(Side.LEFT) == sideLength(Side.RIGHT)) || (sideLength(Side.TOP) == sideLength(Side.BOTTOM));
    }
    public double perimeter() {
        return sideLength(Side.LEFT) + sideLength(Side.TOP) + sideLength(Side.RIGHT) + sideLength(Side.BOTTOM);
    }
    public double area() {
        double c = sideLength(Side.LEFT); // боковая сторона
        double a = sideLength(Side.TOP); // верхнее основание
        double d = sideLength(Side.RIGHT); // боковая сторона
        double b = sideLength(Side.BOTTOM); // нижнее основание
        double temp = (a + c + d - b) * (a + d - b - c) * (a + c - b - d) * (b + c + d - a);
        return (a + b) / (4 * Math.abs(a - b)) * Math.sqrt(Math.abs(temp));
    }
}
